home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / hostname.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2008-10-14  |  1KB  |  54 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          hostname
  4. # Required-Start:
  5. # Required-Stop:
  6. # Should-Start:      glibc
  7. # Default-Start:     S
  8. # Default-Stop:
  9. # Short-Description: Set hostname based on /etc/hostname
  10. # Description:       Read the machines hostname from /etc/hostname, and
  11. #                    update the kernel value with this value.  If
  12. #                    /etc/hostname is empty, the current kernel value
  13. #                    for hostname is used.  If the kernel value is
  14. #                    empty, the value 'localhost' is used.
  15. ### END INIT INFO
  16.  
  17. PATH=/sbin:/bin
  18.  
  19. . /lib/init/vars.sh
  20. . /lib/lsb/init-functions
  21.  
  22. do_start () {
  23.     [ -f /etc/hostname ] && HOSTNAME="$(cat /etc/hostname)"
  24.  
  25.     # Keep current name if /etc/hostname is missing.
  26.     [ -z "$HOSTNAME" ] && HOSTNAME="$(hostname)"
  27.  
  28.     # And set it to 'localhost' if no setting was found
  29.     [ -z "$HOSTNAME" ] && HOSTNAME=localhost
  30.  
  31.     [ "$VERBOSE" != no ] && log_action_begin_msg "Setting hostname to '$HOSTNAME'"
  32.     hostname "$HOSTNAME"
  33.     ES=$?
  34.     [ "$VERBOSE" != no ] && log_action_end_msg $ES
  35.     exit $ES
  36. }
  37.  
  38. case "$1" in
  39.   start|"")
  40.     do_start
  41.     ;;
  42.   restart|reload|force-reload)
  43.     echo "Error: argument '$1' not supported" >&2
  44.     exit 3
  45.     ;;
  46.   stop)
  47.     # No-op
  48.     ;;
  49.   *)
  50.     echo "Usage: hostname.sh [start|stop]" >&2
  51.     exit 3
  52.     ;;
  53. esac
  54.